package com.rush.manageepac.service.impl;

import com.rush.manageepac.dao.NATHouseDao;
import com.rush.manageepac.entity.NATHouse;
import com.rush.manageepac.service.intf.NATHouseService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NATHouseServiceImpl implements NATHouseService {
    @Autowired
    private NATHouseDao dao;
    @Override
    public R save(NATHouse natHouse) {
        System.out.println(natHouse);
        if(dao.save(natHouse)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }


    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String region, int page, int limit) {
//        if(name!=null && name.length()>0){
        if(StringUtil.isNotEmpty(region)){
            region="%"+region+"%";
        }else{
            region=null;
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(region),dao.selectPage(region,start,limit));
    }

    @Override
    public R update(NATHouse natHouse) {
        if(dao.update(natHouse)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
}
